package com.edu;

import java.awt.Point;

public class Circle {

	public int x, y, vx, vy;

	private int r;

	public boolean isfilled = false;
	public Circle(int x, int y, int r, int vx, int vy) {
		super();
		this.x = x;
		this.y = y;
		this.r = r;
		this.vx = vx;
		this.vy = vy;

	}

	public int getR() {
		return r;
	}

	public void move(int minx, int miny, int maxx, int maxy) {
		x += vx;
		y += vy;
		checkCollision(minx,miny,maxx,maxy);
	}

	// 碰撞检测
	public void checkCollision(int minx, int miny, int maxx, int maxy) {
		if (x - r < minx)  {x = r;		 vx = -vx;}
		if (x + r >= maxx) {x = maxx - r;vx = -vx;}
		if (y - r < miny)  {y = r;		 vy = -vy;}
		if (y + r >= maxy) {y = maxy - r;vy = -vy;}
	}
	/**
	 * 判断鼠标点击的位置是否在圆内
	 * @param p
	 * @return
	 */
	public boolean contain(Point p) {
		return (Math.pow(x-p.x,2) + Math.pow(y-p.y,2) <= Math.pow(r,2));
	}
}
